package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.OrderDetailBean;
import com.mz.ozy.mvp.model.BuyKtModel;
import com.mz.ozy.mvp.view.BuyKtContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class BuyKtPresenter extends BasePresenterImpl<BuyKtContract.View> implements BuyKtContract.Presenter {

    private BuyKtModel mModel;

    public BuyKtPresenter() {
        mModel = new BuyKtModel();
    }


    @Override
    public void geAssetsInfo(Activity activity, String id) {
        mModel.geAssetsInfo(activity, id)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<OrderDetailBean>(mView) {
                    @Override
                    public void onSuccesss(OrderDetailBean bean) {
                        mView.geAssetsInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void onPay(Context context, String orderid, String msg) {
        mModel.onPay(context, orderid, msg)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<OrderDetailBean>(mView) {
                    @Override
                    public void onSuccesss(OrderDetailBean bean) {
                        mView.onPaySuccess(bean);
                    }
                });
    }

    public void cancelOrder(Context context, String orderid) {
        mModel.cancelOrder(context, orderid)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<OrderDetailBean>(mView) {
                    @Override
                    public void onSuccesss(OrderDetailBean bean) {
                        mView.cancelOrderSuccess(bean);
                    }
                });
    }
}
